class Solution {
public:
    int tribonacci(int n) {
        int a = 0, b = 1, c = 1;
        int ans = n == 0 ? 0 : 1;

        for (int i = 3; i <= n; i++)
        {
            ans = a + b + c;
            a = b;
            b = c;
            c = ans;
        }

        return ans;
    }
};